package com.welove.fragments;

import java.util.ArrayList;
import java.util.List;
import com.welove.R;
import com.welove.adapter.FriendAdapter;
import com.welove.refresh.PullToRefreshBase;
import com.welove.refresh.PullToRefreshListView;
import com.welove.refresh.PullToRefreshBase.OnRefreshListener;
import android.app.Activity;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

public class FriendFragment extends Fragment {

	View rootView;
	private ListView mListView;
	private FriendAdapter mAdapter;
	private PullToRefreshListView friend_lv_recomm;
	 private boolean mIsStart = true;
	@Override
	public void onAttach(Activity activity) {
		// TODO Auto-generated method stub
		super.onAttach(activity);

	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onActivityCreated(savedInstanceState);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {

		if (friend_lv_recomm == null) {

			friend_lv_recomm = new PullToRefreshListView(getActivity());

			friend_lv_recomm.setPullLoadEnabled(false);
			friend_lv_recomm.setScrollLoadEnabled(true);

			mAdapter = new FriendAdapter(getActivity());
			mListView = friend_lv_recomm.getRefreshableView();
			mListView.setDivider(null);
			mListView.setVerticalScrollBarEnabled(false);
			mListView.setFadingEdgeLength(0);
			mListView.setFastScrollEnabled(false);
			mListView.setDividerHeight(1);
			mListView.setCacheColorHint(Color.TRANSPARENT); 
			List<String> dataList = new ArrayList<String>();
			for (int i = 0; i < 21; i++) {
				dataList.add("hello");
			}
			mAdapter.setData(dataList);
			mListView.setAdapter(mAdapter);
			friend_lv_recomm.setOnRefreshListener(new OnRefreshListener<ListView>() {
		            @Override
		            public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) {
		               
		              
		            }

		            @Override
		            public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) {
		               
		              
		            }
		        });
		       
//		        
//		    friend_lv_recomm.doPullRefreshing(true, 500);

		}
		// 缓存的rootView需要判断是否已经被加过parent，
		// 如果有parent需要从parent删除，要不然会发生这个rootview已经有parent的错误。
		ViewGroup parent = (ViewGroup) friend_lv_recomm.getParent();
		if (parent != null) {
			parent.removeView(friend_lv_recomm);
		}

		return friend_lv_recomm;
	}

}
